package com.me.web.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.me.common.annotation.Log;
import com.me.common.constant.UserConstants;
import com.me.common.core.controller.BaseController;
import com.me.common.core.domain.AjaxResult;
import com.me.common.core.page.TableDataInfo;
import com.me.common.enums.BusinessType;
import com.me.common.utils.StringUtils;
import com.me.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.me.web.system.domain.SysGroupRole;
import com.me.web.system.service.SysGroupRoleService;


/**
 * 用户组和角色关联Controller
 *
 * @author me
 * @date 2024-06-22
 */
@RestController
@RequestMapping("/system/sysGroupRole")
public class SysGroupRoleController extends BaseController {
    @Autowired
    private SysGroupRoleService sysGroupRoleService;

    /**
     * 查询用户组和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGroupRole sysGroupRole) {
        startPage();
        List<SysGroupRole> list = sysGroupRoleService.queryList(sysGroupRole);
        return getDataTable(list);
    }

    /**
     * 导出用户组和角色关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:export')")
    @Log(title = "用户组和角色关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGroupRole sysGroupRole) {
        List<SysGroupRole> list = sysGroupRoleService.queryList(sysGroupRole);
        ExcelUtil<SysGroupRole> util = new ExcelUtil<SysGroupRole>(SysGroupRole.class);
        util.exportExcel(response, list, "用户组和角色关联数据");
    }

    /**
     * 获取用户组和角色关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId) {
        return success(sysGroupRoleService.get(groupId));
    }

    /**
     * 新增用户组和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:add')")
    @Log(title = "用户组和角色关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGroupRole sysGroupRole) {
        return toAjax(sysGroupRoleService.insert(sysGroupRole));
    }

    /**
     * 修改用户组和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:edit')")
    @Log(title = "用户组和角色关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGroupRole sysGroupRole) {
        return toAjax(sysGroupRoleService.update(sysGroupRole));
    }

    /**
     * 删除用户组和角色关联
     */
    @PreAuthorize("@ss.hasPermi('system:sysGroupRole:remove')")
    @Log(title = "用户组和角色关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds) {
        return toAjax(sysGroupRoleService.delete(groupIds));
    }
}
